# My pseudo code for Exercice 4
# START 
#     Make a connection between two items in the bracket_map
#     stack <- []
#     s <- READ a string 
#     FOR each item in s:
#         IF item is one of the values in the bracket_map then:
#             Add the item to the stack
#         END IF
#         ELIF item is one of the keys in the bracket_map then:
#             IF not item can make a pair with it or stack.pop()!= bracket_map[char]:
#                 RESULT=False
#         END ELIF
#         ELSE then:
#             RESULT=False
#         END ELSE
#     END FOR
#     RESULT <- not stack 
# END 
def isValid(s:str):
    bracket_map = {')':'(','}':'{',']':'['}
    stack=[]
    for char in s:
        if char in bracket_map.values(): 
            stack.append(char)
        elif char in bracket_map.keys(): 
            if not stack or stack.pop()!=bracket_map[char]:
                return False
        else:
            return False
    return not stack
print(isValid("()"))      
print(isValid("({[]})"))  
print(isValid("{[])}"))  

